// pages/room/room.js
const config = require('../../config.js')
const http = require('../../http.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    pageSize:10,
    keyword:'',
    catId:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.keyword) {
      this.setData({
        keyword: options.keyword
      })
    }
    if (!app.globalData.isLogin) {
      wx.navigateTo({
        url: '../login/login',
      })
      return
    }
    this.getCivilContent();
  },
/**
   * 监听搜索
   */
  listenersearchInput:function(e){
    this.setData({
      keyword:e.detail.value
   })      
  },

  searchBar: function (e) {
    let keyword=this.data.keyword;
    if(keyword!=undefined && keyword !=""){
      this.getCivilContent();
    }else{
      wx.showToast({
        title: "请输入关键字",
        icon: 'none',
      })
    }
  },

  tapItem: function(res){
    this.getCivilContent('',res.detail.itemid);
    this.hideModal();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  getCivilContent: function () {
    var that = this
    http.request(
      config.getCivilList,
      'get', {
        page :this.data.page ,
        pageSize :this.data.pageSize ,
        search :this.data.keyword ,
        catId:this.data.catId
      },
      function (res) {
        if (res.rows!= null) {
          that.setData({
              listData: res.rows,
          })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },
  shareCount:function(){
    console.log("分享次数")
    var that = this
    http.request(
      config.meetings + "/" + this.data.roomId + "/share",
      'POST', null,
      function (res) {
        if (res.data != null) {
          that.data.meetingData.countShare = res.data
          that.setData({
            meetingData: that.data.meetingData
          })
        }
      },
      function (err) {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      }
    )
  }
})